//
//  OpenShowAnimationController.swift
//  elarc01
//
//  Created by elarc on 16/3/18.
//  Copyright © 2016年 elarc. All rights reserved.
//

import Foundation

    class OpenShowAnimationViewController: UIViewController,HolderViewDelegate{
        var holderView = HolderView(frame: CGRectZero)
        
        override func viewDidLoad() {
            view.backgroundColor = UIColor.whiteColor()
            let bgImageView:UIImageView = UIImageView(image: UIImage(named:"版权小站3"))
            bgImageView.frame = view.frame
            view.addSubview(bgImageView)
            super.viewDidLoad()
        }
        
        override func viewDidAppear(animated: Bool) {
            super.viewDidAppear(animated)
            addHolderView()
        }
        
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
        }
        
        func addHolderView() {
            let boxSize: CGFloat = 100.0
            holderView.frame = CGRect(x: view.bounds.width / 2 - boxSize / 2,
                y: view.bounds.height / 2 - boxSize / 2,
                width: boxSize,
                height: boxSize)
            holderView.parentFrame = view.frame
            holderView.delegate = self
            view.addSubview(holderView)
            holderView.addOval()
        }
        
        func animateLabel() {
            // 1
            holderView.removeFromSuperview()
            view.backgroundColor = UIColor.blueColor()
            
            // 2
            let label: UILabel = UILabel(frame: view.frame)
            label.textColor = UIColor.blackColor()
//            label.font = UIFont(name: "HelveticaNeue-Thin", size: 170.0)
            label.font = UIFont.systemFontOfSize(80)
            label.textAlignment = NSTextAlignment.Center
            label.text = "一拉克"
            label.transform = CGAffineTransformScale(label.transform, 0.25, 0.25)
            view.addSubview(label)
            
            // 3
            UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.1, options: UIViewAnimationOptions.CurveEaseInOut,
                animations: ({
                    label.transform = CGAffineTransformScale(label.transform, 4.0, 4.0)
                }), completion: { finished in
                    ///  点击执行
//                    self.addButton()
                    /// 直接执行
                    UIView.animateWithDuration(0.2, animations: { () -> Void in
                        let adVc:ADViewController = ADViewController()
                        adVc.loadADRootViewController()
                    })
  
            })
        }
        
        func addButton() {
            let button = UIButton()
            button.frame = CGRectMake(0.0, 0.0, view.bounds.width, view.bounds.height)
            button.addTarget(self, action: #selector(OpenShowAnimationViewController.buttonPressed(_:)), forControlEvents: .TouchUpInside)
            view.addSubview(button)
        }
        
        func buttonPressed(sender: UIButton!) {
            view.backgroundColor = UIColor.whiteColor()
            view.subviews.map({ $0.removeFromSuperview() })
            holderView = HolderView(frame: CGRectZero)
            
            let adVc:ADViewController = ADViewController()
            adVc.loadADRootViewController()
        }
    }